package serveur.vue;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JPanel;

import serveur.controller.Serveur;

public class ImageVue extends JPanel{

	private static final long serialVersionUID = 1L;

	private Image image;
	File file;
	public ImageVue(){
		super();
		this.setPreferredSize(new Dimension(100,100));
		this.file = new File(Serveur.cheminDossier+"default.jpeg");
		loadImage();
	}
	
	public void setImage(String value){
		if (value.equals("Selectioner une image")){
			this.file = new File(Serveur.cheminDossier+"default.jpeg");
		}else{
			this.file = new File(Serveur.cheminDossier+value+".jpeg");	
		}
		loadImage();
	}
	
	private void loadImage() {
	try {
			image=(ImageIO.read(file));
		} catch (IOException e) {
			System.out.println("pb image");
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		image = image.getScaledInstance(100, 100, Image.SCALE_DEFAULT);
		repaint();
	}
	public void paintComponent(Graphics g){
		super.paintComponent(g);
		g.drawImage(image,0,0,null);
	}
	
}
